<?php

namespace app\admin\controller\union;
/* 超推每日收益 */

use app\admin\library\Auth;
use app\admin\model\Admin;
use app\admin\model\union\Guild;
use app\admin\model\union\GuildCashOut;
use app\common\controller\Backend;

class Cashout extends Backend
{
    protected $model = null;
    protected $searchFields = '';
    protected $admin_id = null;
    protected $guild_id = 0;
    protected $guild_manage_id = 0;
    public function _initialize()
    {
        parent::_initialize();
        //获取后台登录管理员id
        $auth = Auth::instance();
        $this->admin_id = $auth->isLogin() ? $auth->id : 0;
        $this->assign('admin_id', $this->admin_id);
        $this->guild_id = Admin::get(intval($auth->id))['guild_id'];
//        if($this->guild_id)$this->guild_manage_id = Guild::where('guild_id',$this->guild_id)->value('id');
        $this->model = new GuildCashOut();

    }

    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);

        if ($this->request->isAjax()) {

            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model->where($where)->where('guild_manage_id',$this->guild_id)->order($sort, $order)->paginate($limit);
            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }

        return $this->view->fetch();
    }

}